<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>购物车</title>
<jsp:include page="header.jsp"></jsp:include>
<style>
	.my-cell-row {
		width: 100%;
		margin: 10px 10px;
	}
	 .weui-media-box_appmsg .weui-media-box__hd img{
		width: 100%;
		height: 100%;
	} 
	.my—div span {
		font-size:16px;
	}
	#form {
		display: none;
	}
</style>
</head>
<body ontouchstart>
<div class="weui-content">
<c:choose>
	<c:when test="${not empty list}">
	<c:forEach var="app" items="${list}" varStatus="st">
  <div class="weui-panel weui-panel_access">
    <div class="weui-panel__hd"><span>顺一药房</span><a href="javascript:;" class="wy-dele"></a></div>
    <div class="weui-panel__bd">
      <div class="weui-media-box_appmsg pd-10">
        <div class="weui-media-box__hd check-w weui-cells_checkbox">
          <label class="weui-check__label" for="${app.id}">
            <div class="weui-cell__hd cat-check"><input type="checkbox" class="weui-check" name="cartpro" id="${app.id}" value="${app.goodsPrice*app.goodsNumber}" onclick="bigChange(this)"/><i class="weui-icon-checked"></i></div>
          </label>
        </div>
        <div class="weui-media-box__hd"><a href="javascript:;"><img class="weui-media-box__thumb" src="${pageContext.request.contextPath }${app.goodsPic}" alt="" /></a></div>
        <div class="weui-media-box__bd">
          <h1 class="weui-media-box__desc"><a href="${pageContext.request.contextPath }/phone/detail?id=${app.goodsId}" class="ord-pro-link">${app.goodsName}</a></h1>
          <div class="clear mg-t-10">
            <div class="wy-pro-pri fl">¥<em class="num font-15">${app.goodsPrice}</em></div>
          </div>
          <div class="clear my—div">
            	<span>×</span>${app.goodsNumber}
            	<input type="hidden" value="${app.goodsPrice*app.goodsNumber}"/>
          </div>
        </div>
      </div>
    </div>
  </div>
  </c:forEach>
  </c:when>
  <c:otherwise>
		<div class="my-cell-row">
			<span>您还没有购买药品!</span>
		</div>
		</c:otherwise>
	</c:choose>
  </div>
<!--底部导航-->
<div class="foot-black"></div>
<div class="weui-tabbar wy-foot-menu">
  <div class="npd cart-foot-check-item weui-cells_checkbox allselect">
    <label class="weui-cell allsec-well weui-check__label" for="all">
        <div class="weui-cell__hd">
          <input type="checkbox" class="weui-check" name="all-sec" id="all">
          <i class="weui-icon-checked"></i>
        </div>
        <div class="weui-cell__bd">
          <p class="font-14">全选</p>
        </div>
    </label>
  </div>
  <div class="weui-tabbar__item  npd">
    <p class="cart-total-txt">合计：<i>￥</i><em class="num font-16" id="zong">0.00</em></p>
  </div>
  <form id="form" action="/phone/toCartOrder" method="post">
        <input name="ids" type="text" id="my_id"/>
   </form>
  <a href="javascript:;" class="red-color npd w-90 t-c" id="my_pay">
    <p class="promotion-foot-menu-label">去结算</p>
  </a>
</div>
<jsp:include page="foot.jsp"></jsp:include>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.Spinner.js"></script>
<script type="text/javascript">
$(function(){
	$(".Spinner").Spinner({value:1, len:3, max:999});
});
</script>
<!---全选按钮-->
<script type="text/javascript">
$(document).ready(function () {      
	$(".allselect").click(function () {
		var sum=0;
		var rs ;
		if($(this).find("input[name=all-sec]").prop("checked")){
			$("input[name=cartpro]").each(function () {
				$(this).prop("checked", true);
				sum+=($(this).val()*100)
			});
			 rs=(sum/100).toFixed(2);
			$('#zong').html(rs);
		}else{
			rs=sum.toFixed(2);
			$('#zong').html(rs);
			$("input[name=cartpro]").each(function () {
				$(this).prop("checked", false);
			});
   		}
	});
	
	$('#my_pay').click(function(){
		var url="/phone/cartOrder";
		var str ="";
		$("input[name=cartpro]").each(function () {
			if ($(this).prop("checked")) {
				if(this.id!=""){
					str+=this.id+",";
				}
			} 
		});
		$.post(url,{buys:str},function(data){
			if(""==data||"error"==data){
				$.toast("购买不成功，请稍后在试试!","text");
			}else{
				$('#my_id').val(data);
				$("#form").submit();
			}
		});
	});
});
</script>
<script>
      $(document).on("click", ".wy-dele", function() {
        $.confirm("您确定要把此商品从购物车删除吗?", "确认删除?", function() {
        	
          $.toast("药品已经删除!");
        }, function() {
          //取消操作
        });
      });
		function bigChange(obj){
			var ss =parseFloat(obj.value)*100;
			var $that =$('#zong');
			 if (obj.checked) {
				 var zong1 =parseFloat($that.html())*100;
				 var zz=((ss+zong1)/100).toFixed(2);
				 $that.html(zz);
			 }else{
				 var zong1 =Math.floor(parseFloat($that.html())*100);
				 var yy=((zong1-ss)/100).toFixed(2);
				 $that.html(yy);
			 }
		}
    </script>

</body>
</html>